﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;


public class lists : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        string onlyId = context.Request.Headers["X-ACCESS-USER"];//Header中的token

        if (string.IsNullOrEmpty(onlyId))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;



        using (Entities bll = new Entities())
        {


            var myclass = bll.S_Classs.Where(x => x.SCpareID == 1).ToList();//全部.ToList();
            ArrayList singtask = new ArrayList();
            ArrayList vrtask = new ArrayList();


            ArrayList WWHHtask = new ArrayList();

            foreach (var mcx in myclass)
            {

                var task = bll.S_Goods.Where(xxx => xxx.childClassId == mcx.SCID && xxx.GState != 2);//全部.ToList();
                var endsint = 0;
                var endvr = 0;
                foreach (var x in task)
                {
                    var ispoint = bll.P_T_Sign.FirstOrDefault(s => s.TaskID == x.GID && s.UserId == onlyId && s.State == 1);
                    if (ispoint != null)
                    {
                        endsint++;
                    }
                    var ispointvr = bll.P_T_Sign.FirstOrDefault(s => s.TaskID == x.GID && s.UserId == onlyId && s.State == 2);
                    if (ispointvr != null)
                    {
                        endvr++;
                    }

                }


                singtask.Add(new
                {
                    timg = methods.getFirstImg(mcx.SCSIMG),
                    name = mcx.SCNmae,
                    sintasknu = task.Count(),
                    endsint,
                    scale = 10,  //比例尺10-16
                });

                vrtask.Add(new
                {
                    timg = methods.getFirstImg(mcx.SCSIMG),
                    name = mcx.SCNmae,
                    vrsknu = task.Count(),
                    endvr,
                    scale = 10,  //比例尺10-16
                });



                foreach (var myx in task)
                {

                    var whtask = bll.P_Task.Where(x => x.PointID == myx.GID).ToList();//全部.ToList();
                    var endwh = 0;
                    var nuwh = 0;
                    foreach (var myda in whtask)
                    {
                        var ptdetail = bll.P_T_Detail.OrderByDescending(xx => xx.id);//全部.ToList();

                        foreach (var whendtask in ptdetail)
                        {

                            var sispointvr = bll.P_T_Detail.FirstOrDefault(s => s.TaskID ==whendtask.TaskID && s.UserId == onlyId && s.State != 2);
                            
                           if (sispointvr != null)
                            {
                                endwh++;
                            }


                        }


                        if (ptdetail != null)
                        {
                            nuwh = ptdetail.Count();
                            endsint++;

                        }


                    }

                    var myimgs = methods.GetImgs(myx.GImg);
                    WWHHtask.Add(new
                    {
                        id = myx.GID,
                        content_images = myimgs,
                        myx.GName,
                        nuwh,
                        endwh
                        //myx.GCounts,

                    });


                };





            }





            context.Response.Write(JsonConvert.SerializeObject(new { code, msg, time, singtask, vrtask, WWHHtask }));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }




}